package day1201_3;

import java.sql.*;

public class D1 {

    static  ThreadLocal tl=new ThreadLocal();//书包(电脑)

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection conn=getConn();
    }


    static Connection  getConn() throws ClassNotFoundException, SQLException {//1.从tl书包中取作业本
        Connection  conn=(Connection) tl.get();//1.从tl获取连接对象
        if(conn==null){//2.如果没获取到对象就创建连接对象
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/employee?serverTimezone=GMT%2B8&useSSL=false","root","root");
            tl.set(conn);
        }
        return  conn;
    }


}